package www.cskaoyan.com.controller;

import www.cskaoyan.com.bean.Academy;
import www.cskaoyan.com.bean.ClassManager;
import www.cskaoyan.com.service.AcademyManagerService;
import www.cskaoyan.com.service.ClassManagerService;
import www.cskaoyan.com.service.impl.AcademyManagerServiceImpl;
import www.cskaoyan.com.service.impl.ClassManagerServiceImpl;
import www.cskaoyan.com.utils.Request;
import www.cskaoyan.com.utils.Response;

import java.sql.SQLException;
import java.util.List;

/**
 * 学院管理
 */
public class AcademyManagerController {

    // 调用逻辑层
    AcademyManagerService academyManagerService; // 学院管理的逻辑层
    public AcademyManagerController(){
        this.academyManagerService = new AcademyManagerServiceImpl();
    }


    /**
     * 创建学院
     * @param request:Request{url='AcademyManager/create', methods='POST',}
     *  @param request: parameters={academyName=计算机}
     * @return Response(200, "成功", true)
     */
    public Response create(Request request)  {
        System.out.println("/AcademyManager/create");
        System.out.println(request);
        Response response;
        Academy academy = new Academy(request.getParameters());
        Integer academyId = null;
        try {
            academyManagerService.create(academy);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        response = new Response(200, "创建成功", true);
        return  response;
    }


    /**
     * 获得学院列表
     * @param request:Request{url='AcademyManager/create', methods='POST',}
     * @return Response(200, "成功", true)
     */
    public Response getAcademyList(Request request)  {
        System.out.println("/AcademyManager/create");
        System.out.println(request);
        Response response;

        // 获取学院列表
        List<Academy> list = null;
        try {
            list = academyManagerService.getAcademyList();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        if (list != null  && list.size() > 0){
            // 存在
            response = new Response(200, "学院列表", true);
            response.setData(list);
        }else {
            // 不存在
            response = new Response(0, "没有学院列表", true);
        }
        return  response;
    }



    /**
     * 删除学院:
     * @param request:Request{url='AcademyManager/create', methods='POST',}
     *  @param request: parameters={id=1}
     * @return Response(200, "成功", true)
     */
    public Response deleteAcademy(Request request)  {
        System.out.println("/AcademyManager/deleteAcademy");
        System.out.println(request);
        Response response;
        Academy academy = new Academy(request.getParameters());
        Integer academyId = null;
        try {
            academyManagerService.deleteAcademy(academy);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        response = new Response(200, "创建成功", true);
        return  response;
    }

}
